var v_settings_= null;
var ImageCut = null;
(function($){
	var defaultSettings={
		uploadUrl:webRootVali+"_upload/upload.action?id=1001",
		swf:webRootVali+'upload/avatar.swf?v=2.1',
		defaltImg:webRootVali+"/upload/default_head.jpg",
		uploadSrc:false,
		width:630,
		height:450,
		callback:function(){},//回调函数
	};

	function ImageAssist(settings) {
	    this.settings = settings;
	    this.dialog=null;
	    return this;
	}
	ImageAssist.prototype = {
		    getTimestamp: function () {
		        return (new Date()).valueOf();
		    },
			initDiv: function () {
				var swf = this.settings.swf;
				var img = this.settings.defaltImg;
				var html = '<div id="altContent">'
				+'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
				+'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'
				+'WIDTH="'+this.settings.width+'" HEIGHT="'+this.settings.height+'" id="myMovieName">'
				+'<PARAM NAME="movie" VALUE="'+swf+'">'
				+'<PARAM NAME="quality" VALUE="high">'
				+'<PARAM NAME="bgcolor" VALUE="#FFFFFF">'
				+'<param name="flashvars" value="imgUrl='+img+'&uploadUrl='+this.settings.uploadUrl+'&uploadSrc='+this.settings.uploadSrc+'" />'
				+'<EMBED src="'+swf+'" quality=high bgcolor=#FFFFFF WIDTH="'+this.settings.width+'" HEIGHT="'+this.settings.height+'" wmode="transparent" flashVars="imgUrl='+img+'&uploadUrl='+this.settings.uploadUrl+'&uploadSrc='+this.settings.uploadSrc+'"'
				+'NAME="myMovieName" ALIGN="" TYPE="application/x-shockwave-flash" allowScriptAccess="always"'
				+'PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">'
				+'</EMBED>'
				+'</OBJECT>'
				+'</div>';
				return html;

			},
			initDialog:function(){
		    	var h=this.settings.height;
		    	var w=this.settings.width;
		    	var v_dialog = dialog({
		    		fixed: true,
		   	     	title: '头像上传',
		   	     	zIndex:99999999
		   	    });
		    	
		    	if(this.settings.uploadUrl==null||this.settings.uploadUrl==''){
		    		var d = dialog({
		    		    title: '提示',
		    		    content: '文件上传URL不允许为空!',
		    		    okValue: '确定',
		    		    ok:true,
		    		});
		    		d.width(200);
		    		d.show();
		    		return;
		    	}
		    	v_dialog.height(h);
		    	v_dialog.width(w);
		    	v_dialog.content(this.initDiv());
		    	return v_dialog;
		    },
			openDialog: function () {
				this.dialog = this.initDialog();
				this.dialog.showModal();
			},
		    closeDialog:function(){
		    	if(this.dialog!=null){
		    		this.dialog.close().remove();
		    		this.dialog=null;
		    	}
		    }
	};
	
	$.fn.imageSwfCut = function (settings) {
		settings = $.extend({}, defaultSettings, settings || {});
		v_settings_ = settings;
		ImageCut = new ImageAssist(settings);
		return ImageCut;
	};
})(jQuery);

function uploadevent(status, picUrl, callbackdata) {
	if(status==-1){
		ImageCut.closeDialog();
	}else{
		v_settings_.callback.call(this,callbackdata,status,picUrl);
		ImageCut.closeDialog();
	}
}

